<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="__PUBLIC__/echarts/echarts.min.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<body>
<div class="layui-fluid main" style="margin: 16px;">
    <div class="site-text site-block">
        <form class="layui-form" action="">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">viatorCodes集合，英文逗号分隔</label>
                <div class="layui-input-block">
                    <textarea name="viatorCodes" placeholder="请输入viatorCodes集合,使用英文逗号分隔" class="layui-textarea"></textarea>
                    <a class="layui-btn layui-btn-normal verifyVaitorCodes" style="margin-top: 8px;">检测viatorCode</a>
                    <a class="layui-btn layui-btn-danger clearVaitorCodes" style="margin-top: 8px;">清空</a>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">viatorCode检测结果</label>
                <div class="layui-input-block">
                    <div class="layui-quote-nm layui-elem-quote viatorCodeResult" style="min-height: 50px;">

                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="correntViatorCodes" value="">
                    <a class="layui-btn pullViatorImagesByCodes">拉取匹配的Viator商品图片</a>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">viatorCode拉取结果</label>
                <div class="layui-input-block">
                    <div class="layui-quote-nm layui-elem-quote pullViatorCodeResult" style="min-height: 50px;">

                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
        //清空viatorCodes
        $('.clearVaitorCodes').click(function () {
            $('textarea[name=viatorCodes]').val('');
        })
        //检测viatorCodes
        $(".verifyVaitorCodes").click(function () {
            var viatorCodes = $('textarea[name=viatorCodes]').val();
            if(viatorCodes=='' || viatorCodes==undefined){
                layer.msg('请输入viatorCodes!');return false;
            }
            viatorCodesArr = viatorCodes.split(',');
            if(viatorCodesArr.length > 10){
                layer.msg('一次性最多刷新10条viator商品!');return false;
            }
            var loading = layer.load(1);
            $.post('/admin/goods/verifyVaitorCodes',{viatorCodes},function (res) {
                layer.closeAll();
                html = '';
                if(res.code > 0){
                    $.each(res.data.viatorCodes,function (i,v) {
                        html += '<div class="layui-form-item">\n' +
                            '                            <label class="layui-form-label">'+v.viatorCode+'</label>\n' +
                            '                            <div class="layui-input-block"><input type="text" class="layui-input" value="'+v.viatorName+'" readonly></div>\n' +
                            '                        </div>';
                    })
                }
                $('input[name=correntViatorCodes]').val(res.data.correntViatorCodes);
                $('.viatorCodeResult').html(html);
            },'json')
            return false;
        })

        //拉取符合的viatorCodes
        $('.pullViatorImagesByCodes').click(function () {
            var correntViatorCodes = $('input[name=correntViatorCodes]').val();
            if(correntViatorCodes=='' || correntViatorCodes==undefined){
                layer.msg('暂未匹配到正确的viatorCodes，请重新点击检测!');return false;
            }

            var loading = layer.load(1);
            $.post('/admin/goods/pullViatorImagesByCodes',{viatorCodes:correntViatorCodes},function (res) {
                layer.closeAll();
                html = '';
                if(res.code > 0){
                    $.each(res.data.data,function (i,v) {
                        html += '<div class="layui-form-item">\n' +
                            '                            <label class="layui-form-label">'+v.code+'</label>\n' +
                            '                            <div class="layui-input-block"><input type="text" class="layui-input" value="'+v.viatorName+'" readonly></div>\n' +
                            '                        </div>';
                    })
                }
                $('.pullViatorCodeResult').html(html);
            },'json')
            return false;
        })
    });
</script>
</body>
</html>